/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.seari.ibp;

import com.seari.bean.OperationLog;
import com.seari.utils.FXHelper;
import java.io.IOException;
import java.net.URL;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Date;
import java.util.ResourceBundle;
import java.util.logging.Level;
import java.util.logging.Logger;
import javafx.animation.Animation;
import javafx.animation.KeyFrame;
import javafx.animation.Timeline;
import javafx.beans.value.ObservableValue;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.control.TableCell;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.stage.Stage;
import javafx.util.Callback;
import javafx.util.Duration;

/**
 * FXML Controller class
 *
 * @author Rainbow
 */
public class FXMLController2 implements Initializable
{

    @FXML
    private Label timelabel;
    
    @FXML
    private TableView mainTable;
    
    @FXML
    private TableColumn<OperationLog,String> dateCol;
    
    @FXML
    private TableColumn<OperationLog,String> stationCol;
    
    @FXML
    private TableColumn<OperationLog,String> systemCol;
    
    @FXML
    private TableColumn<OperationLog,String> descCol;
    
    private ObservableList<OperationLog> operationLogs = FXCollections.observableArrayList();
    
    

    @FXML
    private void leftlabelClick()
    {
        System.out.println("com.seari.ibp.FXMLController2.leftlabelClick()");
        Stage stage = FXHelper.getStageByName("main");
        Scene scene = FXHelper.getSceneByName("left");
        stage.setScene(scene);
        stage.show();
    }

    /**
     * Initializes the controller class.
     */
    @Override
    public void initialize(URL url, ResourceBundle rb)
    {
        System.out.println("com.seari.ibp.FXMLController2.initialize()");
        initClock();
        initMainTable();
    }

    private void initClock()
    {
        Timeline clock = new Timeline(new KeyFrame(Duration.ZERO, (ActionEvent event) ->
        {
            DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
            timelabel.setText(LocalDateTime.now().format(formatter));
        }), new KeyFrame(Duration.seconds(1)));
        clock.setCycleCount(Animation.INDEFINITE);
        clock.play();
    }
    
    private void initMainTable()
    {
        dateCol.setCellValueFactory(new PropertyValueFactory<OperationLog,String>("date"));
        stationCol.setCellValueFactory(new PropertyValueFactory<OperationLog,String>("station"));
        systemCol.setCellValueFactory(new PropertyValueFactory<OperationLog,String>("system"));
        descCol.setCellValueFactory(new PropertyValueFactory<OperationLog,String>("desc"));
        operationLogs.add(new OperationLog(new Date(), "OCC", "EMCS", "TESTLOG"));
        operationLogs.add(new OperationLog(new Date(), "OCC", "EMCS", "TESTLOG2"));
        mainTable.setItems(operationLogs);
    }

}
